<template>
  <div id="teacherlist">
    <div>
      <a-breadcrumb style="margin: 16px 0">
        <a-breadcrumb-item>
          <router-link to="/admin">首页</router-link>
        </a-breadcrumb-item>
        <a-breadcrumb-item>
          <router-link to="/admin/teacher">教师管理</router-link>
        </a-breadcrumb-item>
        <a-breadcrumb-item>教师列表</a-breadcrumb-item>
      </a-breadcrumb>

      <a-layout-content
        :style="{ background: '#fff', padding: '24px', margin: 0, minHeight: '280px' }"
      >
        <a-button type="primary">
          添加讲师
          <a-icon type="inbox" />
        </a-button>

        <div v-if="loading">
          <a-spin tip="加载中...">
            <div class="spin-content">教师列表</div>
          </a-spin>
        </div>
        <div v-if="!loading">
          <a-table :columns="columns" :data-source="teacher_list">
            <span slot="img" slot-scope="text,record">
              <img :src="record.img" class="profile" />
            </span>

            <span slot="action" slot-scope="text,record">
              <a-button type="link" @click="goTo('/admin/teacher/detail/'+record.id)">详情</a-button>
              <a-divider type="vertical" />
              <a-button type="link">修改</a-button>
              <a-divider type="vertical" />
              <a-button type="link">删除</a-button>
            </span>
          </a-table>
        </div>
      </a-layout-content>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
const columns = [
  {
    title: "姓名",
    dataIndex: "name",
    key: "name",
  },
  {
    title: "讲师头像",
    dataIndex: "img",
    key: "img",
    scopedSlots: { customRender: "img" },
  },
  {
    title: "讲师简介",
    dataIndex: "desc",
    key: "desc",
  },

  {
    title: "操作",
    key: "action",
    scopedSlots: { customRender: "action" },
  },
];

export default {
  data() {
    return {
      columns: columns,
    };
  },
  computed: {
    ...mapState(["loading", "teacher_list"]),
  },
  methods: {
    ...mapActions(["getTeacherList"]),
    goTo(url) {
      this.$router.push(url);
    },
  },
  created() {
    this.getTeacherList();
    console.log("this.$route", this.$route);
  },
};
</script>
<style scoped>
.profile {
  width: 50px;
  height: 50px;
  border-radius: 50%;
}
</style>